package com.example.zhihu.fragments;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zhihu.R;
import com.example.zhihu.adapter.SectionsAdapter;
import com.example.zhihu.base.BaseFragment;
import com.example.zhihu.bean.FuliBean;
import com.example.zhihu.presenter.FuliPresenter;
import com.example.zhihu.view.FuliView;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class SectionsFragment extends BaseFragment<FuliPresenter> implements FuliView {
    @BindView(R.id.re)
    RecyclerView mRe;
    private ArrayList<FuliBean.ResultsBean> resultsBeans;
    private SectionsAdapter sectionsAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        mRe.setLayoutManager(new GridLayoutManager(getContext(),2));
        mRe.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL));
        resultsBeans = new ArrayList<>();
        sectionsAdapter = new SectionsAdapter(getContext(), resultsBeans);
        mRe.setAdapter(sectionsAdapter);
    }

    @Override
    protected void initPresenter() {
        mPresenter=new FuliPresenter();
        mPresenter.getdata();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_sections;
    }

    @Override
    public void onSuccess(FuliBean data) {
        resultsBeans.addAll(data.getResults());
        sectionsAdapter.notifyDataSetChanged();
    }

    @Override
    public void onFali(String error) {

    }

    @Override
    public void showToast(String str) {

    }
}
